package com.i.piccommon.config;

import com.i.piccommon.util.MinioUtil;
import io.minio.MinioClient;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.web.servlet.DispatcherServlet;

/**
 * @author lewis
 * @type class
 * @description
 * @since 2024/10/23
 */

@Data
@Configuration
@RequiredArgsConstructor
@ConfigurationProperties(prefix = "minio")
public class MinioConfig {
    private String endpoint;
    private String accessKey;
    private String secretKey;
    private String bucketName;
    private MinioClient minioClient;
    private MinioConfig minioConfig;
    @Bean
    public MinioClient minioClient(){
        return MinioClient.builder()
                .endpoint(endpoint)
                .credentials(accessKey,secretKey)
                .build();
    }
    @Bean
    @ConditionalOnClass(DispatcherServlet.class)
    public MinioUtil minioUtil() {
        return new MinioUtil(minioClient,minioConfig);
    }
}
